package cn.securityformail.rabbitmq.hello;

import cn.securityformail.rabbitmq.util.RabbitMQUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;
import java.io.IOException;
import java.util.concurrent.TimeoutException;

@SuppressWarnings("all")
public class Provide {
    /**
     *
     * @throws IOException
     * @throws TimeoutException
     */
    @Test
    public void send() throws IOException, TimeoutException {

        Connection connection = RabbitMQUtil.getConnection();
        //获得连接通道
        Channel channel = connection.createChannel();
        /**
         * 通道绑定消息队列
         *  1:队列名称,如果队列不存在则自动创建
         *  2:是否持久化队列 true 持久 false 不持久
         *  3:是否独占队列 true 独占 false 不独占
         *  4:是否在消费完成之后自动删除队列 true 删除 false不删除
         */
        channel.queueDeclare("hello",false,false,false,null);
        /**
         * 发布消息
         *  1:路由名称
         *  2:队列名称
         *  3:额外参数
         *  4:消息内容
         */
        for (int i = 0; i < 10000000; i++) {
            if (i%2==0){
                channel.basicPublish("","hello",null,"hello RabbitMQ".getBytes());
            }else {
                channel.basicPublish("","hello",null,"heiheihei RabbitMQ".getBytes());
            }
        }

       RabbitMQUtil.closeConnectionAndChanel(channel,connection);

    }
}
